﻿using Ducu.GLB.Global;
using Ducu.SRV.ServiceInteface;
using Ducu.SRV.ViewModel.Message;
using Ducu.SRV.ViewModel.Shared;
using Ducu.UI.Responsible.Filter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;

namespace Ducu.UI.Responsible.Controllers
{
    [NeedLogOn]
    public class MessageController : BaseController
    {

        #region Constructor

        private IMessageService _messageService;
        public MessageController(IMessageService messageService)
        {
            _messageService = messageService;
        }

        #endregion

        #region Common Actions

        #region URL: /Message/ToMe

        public ActionResult ToMe(int? pageIndex)
        {
            pageIndex = pageIndex ?? 1;

            int pageSize = 5;
            Pager queryPager = new Pager(pageSize, pageIndex.Value);

            int sumOfItems = _messageService.GetToMeCount();

            Pager page = new Pager(pageSize, pageIndex.Value);
            IndexModel model = _messageService.GetToMe(page);

            model.Pager = new _PagerModel
            {
                PageIndex = pageIndex.Value,
                RowSize = 5,
                SumOfPage = queryPager.GetSumOfPage(sumOfItems)
            };

            return View(model);
        }

        #endregion

        #region URL: /Message/FromMe

        public ActionResult FromMe()
        {
            Pager page = new Pager(5, 1);
            IndexModel model = _messageService.GetFromMe(page);
            return View(model);
        }

        #endregion

        #endregion

        #region Ajax

        public JsonResult _HasNew()
        {
            return Json(_messageService.HasNew(), JsonRequestBehavior.AllowGet);
        }

        public void _Read(int id)
        {
            _messageService.Read(id);
        }

        #endregion
    }
}